/*******************************************************************************
 * 
 * Copyright:
 * 
 * License:
 * 
 * Authors: SALMON Charles
 * 
 ******************************************************************************/

/*******************************************************************************
 * 
 ******************************************************************************/

/**
 * Helper to build an AnswerField depending on the nature of the answer
 */
qx.Class.define("bip.ui.form.survey.AnswerFieldBuilder",
{
	statics: {
		build: function(minValue,maxValue, textValues) {
			if (minValue == null) {return null;}
			if (maxValue == null) {return null;}
			if (textValues == null) {return null;}
			
			// textValues to map
			var mapTextValues = {};
			for (var i=0;i<textValues.length;i++) {
				var o = textValues.getItem(i);
				if (o != null) {
					mapTextValues[o.getItem(0)] = o.getItem(1) ;
				}
			}
			
			var choices = [];
			for (var i=minValue;i<=maxValue;i++) {
				var textValue = mapTextValues[i] || i;
				var choice = [i,textValue+""]; // value, label
				choices.push(choice);
			}
			return new bip.ui.form.survey.AnswerFieldRadioGroup(choices);
			
			/*if (maxValue - minValue < 10) {
				var choices = [];
				for (var i=minValue;i<=maxValue;i++) {
					var choice = [i,i+""]; // value, label
					choices.push(choice);
				}
				return new bip.ui.form.survey.AnswerFieldRadioGroup(choices);
			} 
			else {
				var answerField = new bip.ui.form.survey.AnswerFieldSlider();
				answerField.setMinvalue(minValue);
				answerField.setMaxvalue(maxValue);
				return answerField;
			} */
			
		}
	}
});